#include <buola/buola.h>

#if defined BUOLA_HAVE_OPENNI2

#include "ckinectdriver_openni2.h"

namespace buola { namespace cvi {

CKinectDriver::CKinectDriver()
{
    if(openni::OpenNI::initialize()!=openni::STATUS_OK)
        throw XInvalid("can't initialize OpenNI");
    
    CreateDeviceList();
}

CKinectDriver::~CKinectDriver()
{
    openni::OpenNI::shutdown();
}

void CKinectDriver::CreateDeviceList()
{
    openni::Array<openni::DeviceInfo> lDeviceList;
    openni::OpenNI::enumerateDevices(&lDeviceList);
    
    if(lDeviceList.getSize()==0)
    {
        msg_warn() << "can't find any openni device\n";
        return;
    }

    for(int i=0;i<lDeviceList.getSize();i++)
    {
        mDevices.emplace_back(new CKinectDevice(lDeviceList[i]));
    }
}

CKinectDriver &get_kinect_driver()
{
    static CKinectDriver lDriver;
    
    return lDriver;
}

/*namespace cvi*/ } /*namespace buola*/ }

#endif
